package vn.edu.ptithcm.pim.dao;

import vn.edu.ptithcm.pim.dom.University;

import java.util.List;

import org.hibernate.LockMode;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

@SuppressWarnings({ "rawtypes" })
public class UniversityDao extends HibernateDaoSupport {

	public void save(University university) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().save(university);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void saveOrUpdate(University university) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().saveOrUpdate(university);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void lock(University university) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().lock(university, LockMode.NONE);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void delete(University university) {
		try {
			Transaction tx = getSession().beginTransaction();
			getHibernateTemplate().delete(university);
			tx.commit();
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public University merge(University university) {
		try {
			return (University) getHibernateTemplate().merge(university);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public University findById(java.lang.Long id) {
		try {
			return (University) getHibernateTemplate()
					.get(University.class, id);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List findByExample(University university) {
		try {
			return getHibernateTemplate().findByExample("University",
					university);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public List getAll() {
		try {
			return getHibernateTemplate().loadAll(University.class);
		} catch (RuntimeException re) {
			throw re;
		}
	}

}
